package com.iscreen.core.trading.actions.parsers;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import com.iscreen.utils.exceptions.IScreenException;
import com.iscreen.utils.exceptions.IScreenExceptionCodes;

public abstract class BaseDailyDataParser
{
	protected abstract void parseLine(String line) throws IScreenException;

	public void parse(String dataFileName) throws IScreenException
    {
    	System.out.println("Parsing file " + dataFileName);
    	try
		{
			BufferedReader reader = new BufferedReader(new FileReader(dataFileName));
			try
			{
				String line;
				while ((line = reader.readLine()) != null)
				{
					parseLine(line);
				}
			}
			finally
			{
				if (reader != null)
				{
					reader.close();
				}
			}				
		}
		catch (FileNotFoundException e)
		{
			throw new IScreenException(IScreenExceptionCodes.DAILY_DATA_PARSE_ERROR, e);
		}
		catch (IOException e)
		{
			throw new IScreenException(IScreenExceptionCodes.DAILY_DATA_PARSE_ERROR, e);
		}

    }
	
}
